clean up some code according to Paul's suggestions