Improved support for dynamic repositories

New PR for #245 which was buggy
Added it back