Well, my first stab at it is 1057. I haven't fully tested it nor simplified the code much.

Brian