More refeactor bug fixes