Made erase function work faster and modified boundary conditions