Refactor createResponse for fixing bug #21