refectored common code