merge with Maher
fix a bug with Maher's code