Bug fixes, cleaned up routines.