moved p and pd declarations to start of onCommand, making method less
redundant.