fixed issue #370 & #518