fix some of the logical bugs