more cleaups and optimizations