Generalized a hard coded if-statement