updated pooling to handle edge cases