Move some parts into external libraries