Main cycle implemented