Refactored this code.