Updated to use require.resolve and readable code.