Refactored grid class