some renaming, moving code into a more readable order