Fix IE8 issue, cleanup code