trying to reorganize code