Added null check on model encoder