Removed unused code
Removed unused code and some bugs