Large patch from Frank Cusack <fcusack@fcusack.com> to add proper