Cleaned up some code and improved device offline handling
Cleaned up some stuff