how does pain work