refactored for better encapsulation