added rudimentary error handling