Fixed #636 and #648