authenticate code cleanup