added if and loop functionality