Corrected some bugs. Almost done.