fixed bugs + added some syntactic sugar to work with angularjs