patches #5193, #5194, #5195 and #5206 by basinilya