Fix issues #58, #47, #48 and #34