refactors everything

Needs more tests, but this is better