Oh.I didn't notice that collisions sometimes failed to trigger while testing the game. I went through the code and it seems that I messed up some values when checking collisions.
Thanks for the feedback.