refactor lib.rs from functions to a struct