updated for more of the chanage recommended by William Kelly