edited code to get everything working