move code into directive