pie refactored