Moved common code to new file