Fixed #1, #4 and #6.