Refactored some code, add device utils