Serious code cleanup
PEP8 cleanup
Further cleanup and bug fixing