Massive refactorting. Algorithms seem to be buggy, more testing required
asdf