code cleanup, history implementation - . works correctly now.