quick code refactoring from Brian
more quick refactoring post-feedback