Revised version with better sematics