Added some rudimentary error handling