moved cleanConditionally to separate function
moved more logic into functions