general cleanup of code and packet handling fixed