Some debugging added

First release to a buddy of mine showed some obvious flaws in the error
handling and sanity checks. This is a start to fix this.