Cleaned up and refactored run code