applied fixes and some changes, see desc.

also ran auto code formatter