Refactoring a bit and fixing some smaller bugs.