fix NameErrors and ImportErrors
improved flow control
comment improvements
remove unused tests