add code to calculate pole, some fiexes