Incorporated Max's bug fixes from Google group post.