clean-up, performance tweaks, and edge cases