move main to lib