Restructured Javascript code and cut down on number of Ajax lookups