Reworked the main registry code