changed order of a few functions