General refactoring. Grid needs to be fixed.