added error catching
added precondition check