Remove require_once from inside functions

Rebased version of #304