Fixed scoping bug for model API