Define a 'bedstead' directive and move appropriate functionality there from controller.