better debugging, fix potential errors