Extract dependency loading and add unit tests for it