updated and tested