Refactoring, fix gui