Formatting encoding

general formatting fixes and cleaning up the code so we can actually read it