finnished code works great