pushed code into proper files, removed duplicates

- removed some code duplicates
- cleaned up some
- implemented others
- still need tests