working javascript functional design perhaps