SOURCE: lots of refactoring and modularizing