main code, usernames/keys redacted