Refactored a bit for clarity.