Huge refactoring. Project finally works (but not in intellij)