Partially ported to JSTP 0.5