Fixing tests, better error handling

Here's an example of where it bit me once - http://blog.howarddierking.com/2014/03/24/javascript-guard-clauses.html