refactored for more flexible/oo