Corrects various bugs