move few functions around for readability