updated with latest code