Updated to fix a few bugs