cleanup code, fix debug output