Closes #707 untested but should be correct based on all the information I could find Reviewed-on: #1024