fixing various bugs