Removed unnecessary errno resets and did simple cleanups