refactor some code into a function; add sanity_check() function to catch lines/squares out of syn