Updated version of #623. Closes #623. Closes #172.