Minor refactoring in peer and piece code