Adding the bulk of the code