tidy up reading input, avoid leaks, restore sanity