fixed if else control flow in function, still prints warnings