Started writing the main functions