Added rudimentary error handling