Debugged and fixed update logic