code refactoring

some function is so ugly, so I spare some time to refactoint them. Of
course I do not what it will really be, so when a complete something, I
will refactoring again. Maybe this it called ‘iterator’.