fix various bugs