refactored nested ifs... yuck
mc