Moved code within cases to their own functions, making them easier to maintain