fixed buggy javascript