Had to restructure code after Valgrind run

Added several important size constraints,
fixed a huge memory leak using free(packet) m(