added basic error handling stuff