I like the tests!  However, could you please break this function up into a few explanatorially-named functions?