Minor problem fixing and gui code refactoring