Optimized and fixed some things with sleeping.