implemented IF and THEN. make the code more efficient