Cleaned upp rearranged code for API prep.