Main logic implemented