Moving the logic to a directive