Add braces around if
Better handling of incoming parameters
Start using $params arg and create the query string in resource.php layer.