some optimizations and housecleaning