modified to work better with internal and third party modules