modified according to suggestion from dave hunt