Some bugs solved.
code cleanup and refactoring