fixed bugs. Still not bug free