Refactor algorithm helpers