Refactored pig implementation