by Benjamin. Fixed bug 2458 and 2440.