Successfully combined Daniel's code with Greg's