Finished code for ex41 Still need to study it for a while.