Bug fixes, cleanup, code optimization.