Move knockout definition out of if statement