Fix a few things and remove debug code