Managing the commons: a simple model of the emergence of institutions through collective action