added pi current loop and some code changes