Optimize/various

Cleaned a few functions and split items into Def blocks where possible