STY: Refactored simulation code in response to @richafrank's comments.