Fix a bug that cause remove function to return wrong result

origin: for i = 0 -> n-1
fixed: for i = pos -> n-1