refactor idw algorithm