added more error handling stuff