Reorganize code slightly