initial upload, some parts forked from Garwynn XDA and rest from me