Clean up the code according to Paul's suggestion