fixed bugs and removed unnecssary code