More comprehensive error checking and debugging