refactor main. also add class hint for future permutation optimization