Added some error control. More thorough documentation.