use last() instead of pop()