first working prototype (contains hack for #12)