Merge with Tibor's code