A set of commits which should help fixing some bugs

Bug #4240, #4236