Bug Fixes and Erase Zero Elements

Fixed some bugs and now it cleans zero memory elements