Bug fix #10, #22, #23 and #32