Correct various bugs