refactor... lots of it