Javascript simplified and fixed.