refactored legacy code