simpler version without if statement in the function