catch errors, remove redundant debug code, small fixes