bugs and refactoring of simulator