Changed position of dist allocation.

This is to allow the removal of extra zeroes without wasting memory. A goto statement replaced the return statement to make sure all the used memory was freed.