final version with everything working