Clean up code for idle function