Cleaned up the redrawing function