Added common code for all functions