substantial code refactoring