Move server core code to /lib