slightly better error handling
some comments, more error handling