Remove superfluous ) from the html entities encoding function. It was breaking things just a little bit!!