index out of bounds when using last post