Refactor: Move code from main into packages and self contained structs/interfaces to improve code modularity.