refactor and break down into modules.