refactor code to use list