Updated class structure and fixed some bugs.