Refactored and tidy up.