Fix several reported issues: #45 and #46