improved lifecycle handling and tests