Moving functionality to lib