cleaned up code, improved testing level