adding untested code
also implementing exception handling