re-organized and trailing whitespace function