Fixed a bug with the run history + code factorization + code cleanup