Create and delete repository

... and some internal refactoring.