fixed several bugs and leaks, still need to work on alts with common refs