Clean up syntax a bit by pulling out functions and destructuring