Refactored logic out into a prototype