added tests cleaned up exception handling