Taking Daniel's code.