Huge refactor. ;/