Refactored a bit.