Add better error logging