Improved key detection to handle lines which have colons in them