bug fixes from merge, compiles but not tested