Half buggy, overzealous javascript