finished and tested code