reorganize code a bit