refactored per comments