Bugs fixed and unused code removed