Added more documentation, and better error messages.