added __name__ check, improved formatting