Refactored a little to tidy up.