refactored server side packet handling functions and select()