Added semi-colon.
Simplified directive.
Moved functions around so that all scope event-handlers are next to each other.