Refactoring. making way simpler. inspired by the JS version of this app