Initial implementation of #36 and #37.