Code cleanup and jQuery 1.7+ compatibility