refactor some simple for code