Fix code issues and refactor the repositories