Refactored evolution code