issue #6, cleanup messy code