some changes as advised by Mark Wieder