finished rewrite in angular+require, it is beautiful