Some optimizations, cleanups and TODO additions