Move some function into core