Optimiser improvement

Added a timeout for parsing queries in optimiser.