removed test and tightened up code