Add more error codes, messages and error checking.

http://pastebin.com/raw.php?i=Nb36097F seems to work just fine, actually. Unless I'm missing something?