move directive controller into a factory