improved exceptions. Added docstrings.