Applied proper angularJS practices and fixed bugs in SPA

see commit messages about the changes I did