finalized code

finalized code