Fix bugs #32 and #36, fix enhancement #33