Move library loading code based on os name/architecture to one function