Common factor extraction to simplify the code a little