dividing into functions, cleaning stuff