Adding more debugging and some light error handling