Factorised some lines. Not tested since I screwed up my SD card