reorganises code