Extracted functionality from read_command to separate functions