factor out library into different files
WIP