added error handling stuff