Moved check for exceptions into more appropriate spot in order to guarantee location of the exception being thrown.