Finish the predict function clean up the code