bugfix for issue #16

@eile  this should fix issue #16.

While working on the fix, I noticed a performance issue that will hit if the requested size is large but the stored size is small. I'll commence work on a fix for that too.
Either way, this should restore functionality for the failing test case.

std::min()?