Refactor /offline and /lib

Refactor /offline, /lib and some other affected files