Javascript: Filling in the cracks