finished the code, comments still needed