Minor improvement to logic