Fix #464 and #535