I was replacing a ceiling fan it seemed like it was added after the house was built. I took the fan off and removed the circle mounting bracket / box for the fan and all it was a ceiling wall with a romex wire sticking out. I was under the impression you needed a electrical box, the fan box itself is almost like a electrical like box and it has a couple of wood screw holding it to a stud above the ceiling drywall. I was wondering this is to code or not?