Fix all bug and revert some commit that causes a crash