small optimization, avoid insert and pop

Instead replaces last value of list. From what I can see, this is the intention of the previous code.
Merge pull request #54 from zeffii/patch-1

small optimization, avoid insert and pop