Better error handling and comments/docs.