Refactor

for review
refactorings and minor bugfix preparing for wstool modifications
large code shift moving functions in one commit contains no other functional changes(just removed self. where appropriate)