Clean up code using module `inspect`

The script now contains fewer lines of code and does not access __name__ class
members.