refactor lib part 1