redesign and shorten redundant code