corrected function for fence