lot of optimization/cleanup