refactoring, improved transpose