improvements to both implementations