Move typ outside of the if-block