added a lot of logic fixes. commiting before changing weight algorithm