misc refaoctring
introduce var
misc refactoring