Corrected a few bugs