Cleaning up, correcting small stuff, optimizing loops