Efficiency changes

Changes made for efficiency (pass by const reference). Code cleanup.