Rewriteminor hcanges and enhancements, please check before moving all over