add imporved example code from assignment