separated domain dependent and independent parts. minor cleanup to make it much faster. lab1.py is obsolete as of this commit.