debugged distribution.c and added tests