Fix NPE on all non-Home pages; restructure js.