fix memmory error
fix optimal size update tests
extend tests
add tests