Make internal function more reusable