Rearranged the function layout a bit