Merged in changes to Riad's code.