a huge refactor