added rudimentary error catching