Rearrange towards repository pattern