refactored simulation