finish fix #31, additions not tested for correctness