working algorithm for basic map