further logic bug fixes