changed class design and some functions