Fixed a few bugs and cleaned the debugging