this logic should be tested, and should not be in index.html