merged and changes from jons suggestions