reorganized to be more readable