Done some code cleanup, removing some dead code, correcting some issues.