This code works OK right now - examples of how to use select and alarm are in here.