fixed bug, added test, need to move to IP implementation