Removed unnecessary dynamic memory allocation (fixes #1), better utilization of consts and references (fixes #2)