removed diagonal, refactoring, bug fixes, cleanup