adding better error logging