fix fg_tidy_script & general code cleanup