Some alterations to organize the code