Corrected many bugs.