Fixed a few bugs in preparation.