Handle nil timeout, since system_timer does not
Use encode_to_array to avoid extra copies
Improve timeout specifications