Changed receiving the first ENQ to waitCommEvent and cleaned up a few functions