Add in thread safetly, also do cleaning

Went though and added thread safely related items to the maps which are written and read from to avoid concurrency issues.

Also removed a few nitpicky things.