Fixed item deletion and did some refactoring