Removed unneccesary heap allocation, and ensured deletion of rest