modules.py rewrite and library readability fixes