first solution
add comments and clean up a little