more refactoring of mainform