restructuring lib for server-side processing