First crack at a mostly JS implementation