rearranging code to lib