Improved version for #212