weighted

changed to weighted version, and including some debug outputs