major refactoring of functions with JS' OOP