refactored, re-organized, and improved