Bug fixes on update function