refactor and improvements

developments of the last two weeks, pulled into a new "develop" branch.