Moved logic to new files using custom directives.

Moved logic to separate files using custom Angular directives.