merged some duplicated code into functions