Added boolean and if statement to code