cleanup and re-ordering of code to meet submission requirements