refactored foldRows/foldColumns a bit