Adds optimizations for unused arguments and fixes some bugs.