changed code to work with angular, repackaged as an angular directive