Corrected function bug