fixed bugs, refactoring class hierachy.