added some functionality on Nates work