more debugging
bit more error checking