Lots of improvements on design and functions. Refactoring.