Refactored grid code to allow other grids than SGE