Cleanup the code and fix little errors

Now the code looks much better and builds.