some inlining and moving around