Corrected code with Chase's version