updated code, about to test it