finalized all the code