fixes issues #30 and #21