Upgraded grid calculations

Completely re-written!