Nit: please add a comment explaining what this code does and why it does it. The old code that you are replacing had a simple comment.  Just copying that would be good enough. Or try to do something even better.