finalized the code