finished the code implementation