refactored previous changes a bit