Bug fixes, complete working version.