If and else statement created for function