Issues with picking

I'm designing a program so that you can color the model by using picking. However, whenever I draw on the model, it appears on the back of the model at strange places. I don't know if I'm doing the ray-triangle intersection correctly. Here is my code: