Fix bug #440, #441 and enhance