Very big refactoring and improvemnets in source code.