Added modularization and tests