Improved version of my earlier inject method