Added logging, some cleanup.