added error handling for undefined stocks in query controller