Moved common code a common place