Move code to lib
Fix Makefile