assignment 4 fct/docstring completed. Need comments and optimizations