Started refactoring for better modularity.