Extracts logic to scope