refactored for oo-design and jslint compatability