Added answer to Stack Overflow.