Cleaned code, fixed check: only outputs on change