final fix for periodic function