Fixed a few bugs in the update method