Fix broken images with JS. Closes #387