Further work on the main code