Code reduced and rewritten, included tmhOauth