Minor refactoring of JS code and centralisation of shared classes (into variables).