Have you looked at using the "Proper" formula?

Not sure of your layout but this might be a good start?