refactoring, trying to tie down global vars