Naming of an organic compound How would I determine the systematic name of $\ce{(CH3)2CHCH2CHClCH3}$?

First of all, how do we determine which side we number the carbon atoms from? It has an alkyl group ($\ce{CH3}$) and a functional group ($\ce{Cl}$). I got lucky by going from right to left so I wrote 2-chloro-4-methylpentane but why couldn't we also label this as 4-chloro-2-methylpentane?

Do we take functional groups in preference to alkyl groups when naming them?
The substituents go alphabetically, and as 'chloro' is before 'methyl' in the alphabet, the correct name is 2-chloro-4-methylpentane.