Updating code to fix a few bugs