Refactor lots of stuff