add replace trailing space hook, enhance a bit the grammar