Integer overflow when calculating capacity
Added unit tests