Fixed some bugs

Fixed some bugs and removed a lot of debug output. It's faster and
better now.