refactoring
state cache fix
leak fix
cleanup