Added additional requested behavior and some code cleanup.