Fixed function for calculating next coords