Fixed problems and code cleanup.