split up/simplify code.