This closes #135, and also improve #118