apply preferences, tidy up formatlayout function