Fully implementing RWT
FIX: avoiding sum twice