improve resource counter implementation, add basic documentation.