oop and fixed some bugs