Manual merge. Closes #311, #313, #318