Moved some stuff to lib