major refactoring of code. moved several methods to PI execution area and turned temporary vairables to mutable member fields.