adjusted the changes to match johannes optimizations