cleaned up code a little.  Broke larger functions into smaller ones.