Fix bug which resulted in more items being removed than necessary
Replaced deprecated Exception catching syntax