refactoring...
Complete rewrite...