Corrected the free sampling function