huge refactor. now much better