Major refactoring, most stuff is working again