Started refactoring to split code in various classes