broke the onCommand function up a bit, for readability