Fix for issues #91, #77, #41