modified griding.py