Changed code to use a more elegant solution for backwards compatibility.