Simplified size calculation and fixed multiplication/division mixup (thanks to @pagameba). Added test to verify size calculation.