Fixed the CRE logic and added onchange event