code tweaks merged from luke