fixes bugs on update logic and refactoring