more bug fixes and legacy code removal