add device detect, fix indents and trim comments