Made deallocation function more readable and removed dead code