Errors corrected in the logic