added mark's fix for removing trailing elements in the vector