Function Fixes

Fixed stack issues along with a few minor function optimizations such as
removing needless copies.