Trimmed down the code