refactored; improved