Added better error logging