Tidied sleep code