progress on #61
huge refactor

it compiles at least!