extract directive logic from controller