Refactored implementation to enable accurate replacement with real types