medium-light algo refactor