completed predict function