Avoid copypasta
Fix crash due to invalid memory access

The last element in a vector is size() - 1, no idea how this code even
worked.

Fixes #1
Use vercor's front() and back()

Makes the code a bit more clearer.
Merge pull request #2 from khaledhosny/fix_memory_access

Fix invalid memory access