fixed bug in erase
cleaned up erase implementation