Fix bug #37 and enhancement #38