moved code to a lib structure and add a load function