main class cleanup and bugfixes