improved the organization of the code