Move term-size calculation to separate file and related clean-up