MAJOR overhaul

Pull in LOTS of code changes from vikrant82