moved all logic from controller into directive