some fixes based on Cyrille's code review