code cleanups + perf. improvements