reorganized to make it cleaner