debug and error handling fixes