Make file executable
Rewrite to provide more reliable device detection