refactor list logic into methods and add tests