Optimized autosleep.c