Made the top-level function more general, made tests interactive.