Added exceptions. Improved documentation.