Fixed bugs and deleted old code