Added better error handling stuff