Merge "Reorder setup and cleanup functions for readability"