revised version to make it work