stylistic and memory management fixes