Clean up and modularise