Got rid of hacky WET code with more appreciation for javascript's weird closures.