refactored from solutions