updated with latest version of code