Refactor maingui class for easier development