fixing copy paste error with error checking