Fixed bugs and included nathan's work