Cleaning up code and adding isIdle