Might be worth checking the size of ```lines``` to avoid cryptic IndexErrors from accessing lines[0:5] below.