Replacement for #21

Also fixed #26