finessed error handling & added tests