fixing #328 and #648