moved code to lib