finalized code 2