Pause a moment to gather your thoughts before tefilla. (ShA 1 – MB 1)
It is good to stay after shul until no minyan is left. It is also a mitzva just to be sitting in a bais haknesses. (MB 1)
Lechatchila, the mood for tefilla should be of awe and subjugation. If you can’t muster those feelings, at least rid yourself of any jokes, levity, devarim b’taylim, and anger. (ShA 2 – MB 4)
Words of comfort from the Torah were instituted to say before tefilla in order to arouse feelings of simcha. i.e. redemption from Egypt for Maariv and Shacharis – “R’tzon y’rayov ya’aseh…Shomer Hashem es kol ohavav…” for Mincha and Musaf. Learning p’sak halacha before daavening also arouses simcha. (ShA 2,3 – Rama 3)
L’chatchila, you should not learn pilpul halacha just before daavening so your mind will not be distracted during tefilla. (ShA 3 – MB 5)