move controller functionality to directives