Trying to debug and optimize the code structure to release resorces...