made code shorter with functions