contract PaymentHandler {
	using SafeERC20 for IERC20;

	// a boolean to track whether a Proxied instance of this contract has been initialized
	bool public initialized = false;

	// Keep track of the parent master contract - cannot be changed once set
	PaymentMaster public master;

	/**
	 * General constructor called by the master
	 */
	function initialize(PaymentMaster _master) public {
		require(initialized == false, 'Contract is already initialized');
		initialized = true;
		master = _master;
	}

	/**
	 * Helper function to return the parent master's address
	 */
	function getMasterAddress() public view returns (address) {
		return address(master);
	}

	/**
	 * Default payable function - forwards to the owner and triggers event
	 */
	function() external payable {
		// Get the parent master's owner address - explicity convert to payable
		address payable ownerAddress = address(uint160(master.owner()));

		// Forward the funds to the owner
		Address.sendValue(ownerAddress, msg.value);

		// Trigger the event notification in the parent master
		master.firePaymentReceivedEvent(address(this), msg.sender, msg.value);
	}

	/**
	 * Sweep any tokens to the owner of the master
	 */
	function sweepTokens(IERC20 token) public {
		// Get the owner address
		address ownerAddress = master.owner();

		// Get the current balance
		uint balance = token.balanceOf(address(this));

		// Transfer to the owner
		token.safeTransfer(ownerAddress, balance);
	}

}
/**
 * The payment handler is responsible for receiving payments.
 * If the payment is in ETH, it auto forwards to its parent master's owner.
 * If the payment is in ERC20, it holds the tokens until it is asked to sweep.
 * It can only sweep ERC20s to the parent master's owner.
 */
function initialize(PaymentMaster _master) public {
	require(initialized == false, 'Contract is already initialized');
	initialized = true;
	master = _master;
}

/**
 	 * General constructor called by the master
 	 */