These count assignments seem a bit awkward.  First we are checking if the length of parts is greater than three, if so set count to parts[3], otherwise set count to 1.  Then if length of parts is greater than 5 set it to 5.  Is there a more elegant way of doing this?