One last refactoring of my function (based on other's approaches - yep, I finally peeked).