some work related to #4 and more refactoring/fine tuning