code refactoring (incomplete)