Code refactoring, bug correcting.