Added missing documentation and error checking