Corrected various bugs.