Code from violent Python (some fixes)