refactored to make code more object-oriented
version up