added 90% functionality to grid filter function for nbody