add device detect, fix indents, trim comments and remove echoes