modularise and re-arrange