Remove debugging output, fix some bugs