cleaned up weight code