restructuring of the main code