Fixed missing lines writing during reevalation

+Cleaned up the code.