More error checking and documentation.