Clean up code with small function