More optimization and cleanup