Some bug fixes and cleanup of angularjs code