Fixed bug with broken rowspans. Did some refactoring