Tweak size function to improve speed.

Add tests for size function.