updated to fix sleep and make more modular