Refactoring and added error test for Q param