some more error checking
Some more random hacks