debugged with more complete test