added error handling
added tests for exceptions
added testcases for three usages
refactored to_a
named parameters, comment lines