contract Mortal is Owned {
	/** contract can be closed by the owner anytime after this timestamp if non-zero */
	uint public closeAt;
	/** the edgeless token contract */
	Token edg;
	
	function Mortal(address tokenContract) internal{
		edg = Token(tokenContract);
	}
	/**
	* lets the owner close the contract if there are no player funds on it or if nobody has been using it for at least 30 days
	*/
  function closeContract(uint playerBalance) internal{
		if(closeAt == 0) closeAt = now + 30 days;
		if(closeAt < now || playerBalance == 0){
			edg.transfer(owner, edg.balanceOf(address(this)));
			selfdestruct(owner);
		} 
  }

	/**
	* in case close has been called accidentally.
	**/
	function open() onlyOwner public{
		closeAt = 0;
	}

	/**
	* make sure the contract is not in process of being closed.
	**/
	modifier isAlive {
		require(closeAt == 0);
		_;
	}

	/**
	* delays the time of closing.
	**/
	modifier keepAlive {
		if(closeAt > 0) closeAt = now + 30 days;
		_;
	}
}
/** owner should be able to close the contract is nobody has been using it for at least 30 days */
function closeContract(uint playerBalance) internal{
if(closeAt == 0) closeAt = now + 30 days;
if(closeAt < now || playerBalance == 0){
	edg.transfer(owner, edg.balanceOf(address(this)));
	selfdestruct(owner);
} 
}

/**
 	* lets the owner close the contract if there are no player funds on it or if nobody has been using it for at least 30 days
 	*/