Fixed end if issue