refactored logic for coordinates conversion