Added better error loggin