refactor non-angular code to separate files, add tests