Bug fix! and some cleanup.