Secret Document Code Sync

Syncing code to some changes I made on TGS. Mostly makes the code cleaner.