Completely rewritten JavaScript + listing function.