split into two commands, reorganize code a bit