Huge refactor