Remove some bloat, add in function definitions, and more optimization