fix possible "list index out of range"