Rearranged and cleaned
localized error rather than used pointer directly