got rid of seg fault, outputs commands in order