more funcs to remove duplicated code. a bit messy still