Passed a test for multiple runs and refactored more.