Move persistance handling to a repository + small fixes