Add debug info and error handling