Add assert for !MD_GHOSTS
Move constant values out of loop body