Study explains behavioral reaction to painful experiences