simulator: refactoring and cleanup