Various fixes, removed debug code