move functions around more logically