update directive and clean up some code.