finished the first version of the code