Adding better error logging