adjusted order of code