refined in/out handling
Improved removal of trailing whitespace