Fix for issues #5, #8 and #9