Fix one bug and some cleanups
Fix case where there are duplicate locations in a way.