optimizing predict func