Finished a draft implementation for #44.