dynamically updating the coordinates
further refactoring