fixed while loop and refactored invalid command if statement.