Improved device script