implemented `last` stmt.
refactoring the loop handler