this is a revised version which works now