Fix #304 and #281