fix grid wrapping on all edge cases