cleaned up loose ends - fixed bugs